//格式化时间
export function dateFormat(num, type) {
    const dd = new Date(num);
    const y = dd.getFullYear();
    let m = dd.getMonth() + 1;
    let d = dd.getDate();
    let h = dd.getHours();
    let i = dd.getMinutes();
    let s = dd.getSeconds();
    m = m < 10 ? '0' + m : m;
    d = d < 10 ? '0' + d : d;
    h = h < 10 ? '0' + h : h;
    i = i < 10 ? '0' + i : i;
    s = s < 10 ? '0' + s : s;
    if(type) {
        return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s
    } else {
        return y + '-' + m + '-' + d
    }
}
export function dateFormatChin(num, type) {
    const dd = new Date(num);
    const y = dd.getFullYear();
    let m = dd.getMonth() + 1;
    let d = dd.getDate();
    let h = dd.getHours();
    let i = dd.getMinutes();
    let s = dd.getSeconds();
    m = m < 10 ? '0' + m : m;
    d = d < 10 ? '0' + d : d;
    h = h < 10 ? '0' + h : h;
    i = i < 10 ? '0' + i : i;
    s = s < 10 ? '0' + s : s;
    if(type) {
        return y + '年' + m + '月' + d + '日' + h + ':' + i + ':' + s
    } else {
        return y + '年' + m + '月' + d+ '日'
    }
}
export function stringToDate(strDate){
    const tempStrs=strDate.split(" ");

    const dateStrs=tempStrs[0].split("-");
    const year=parseInt(dateStrs[0],10);
    const month = parseInt(dateStrs[1], 10)-1;
    const day = parseInt(dateStrs[2], 10)
    const timeStrs = tempStrs[1].split(":");
    const hour = parseInt(timeStrs [0], 10);
    const minute = parseInt(timeStrs[1], 10);
    const second = parseInt(timeStrs[2], 10);

    return new Date(year, month, day, hour, minute, second);
}
